/**
 * Copyright (c) 2019 Coder League
 * All rights reserved.
 *
 * File：ThymeleafConfigurer.java
 * History:
 *         2019年6月26日: Initially created, Chrise.
 */
package club.coderleague.cfss.config;

import javax.annotation.Resource;
import javax.servlet.ServletContext;

import org.thymeleaf.spring5.view.ThymeleafViewResolver;

/**
 * Thymeleaf配置器。
 * @author Chrise
 */
public class ThymeleafConfigurer {
	private static final String KEY_CTX = "ctx";
	private static final String KEY_MOBILE_CTX = "mobilectx";
	private static final String KEY_MOBILE_SUPPLIER_CTX = "supplierctx";
	private static final String KEY_MOBILE_CYBERCAFE_CTX = "cybercafectx";
	private static final String KEY_LIB = "lib";
	private static final String KEY_CSS = "css";
	private static final String KEY_IMAGE = "image";
	private static final String KEY_JS = "js";
	
	@Resource
	private ServletContext sc;
	
	/**
	 * 注册静态变量。
	 * @author Chrise 2019年6月26日
	 * @param resolver 视图解析器。
	 */
	@Resource
	private void registerStaticVariable(ThymeleafViewResolver resolver) {
		String ctx = this.sc.getContextPath();
		
		resolver.addStaticVariable(KEY_CTX, ctx);
		resolver.addStaticVariable(KEY_MOBILE_CTX, ctx + "/mobile");
		resolver.addStaticVariable(KEY_MOBILE_SUPPLIER_CTX, ctx + "/mobile/supplier");
		resolver.addStaticVariable(KEY_MOBILE_CYBERCAFE_CTX, ctx + "/mobile/cybercafe");
		resolver.addStaticVariable(KEY_LIB, ctx + "/static/library");
		resolver.addStaticVariable(KEY_CSS, ctx + "/static/css");
		resolver.addStaticVariable(KEY_IMAGE, ctx + "/static/image");
		resolver.addStaticVariable(KEY_JS, ctx + "/static/js");
	}
}
